import java.util.Scanner;

public class Old_1094 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt(),n = sc.nextInt();
        int[][] dp = new int[n+1][m+1];
        int[][] mon = new int[n][2];
        for (int i = 0; i < n; i++) {
            mon[i][0] = sc.nextInt();
            mon[i][1] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                dp[i][j] = dp[i-1][j];
                if (j>mon[i-1][0]&&dp[i-1][j]<dp[i-1][j-mon[i-1][0]]+mon[i-1][0]*mon[i-1][1]){
                    dp[i][j] = dp[i-1][j-mon[i-1][0]]+mon[i-1][0]*mon[i-1][1];
                }
            }
        }
        System.out.println(dp[n][m]);
    }
}
